package rentadomus

class SearchByStringController {

    def index(){
        
        redirect(action: "main", params: params)
    }
    def main(){
        print(params)
        print('%'+params.string+'%')
        def list
        switch (params.SearchBy) {            
            case "Price: Lowest first":                
                list = Place.findAllByTitlePlaceIlikeOrDescriptionIlike('%'+params.string+'%','%'+params.string+'%',[max: 10, sort: "rentPrice", order: "asc", offset: 0])
                break
            case "Price: Highest first":
                list = (Place.findAllByTitlePlaceIlikeOrDescriptionIlike('%'+params.string+'%','%'+params.string+'%',[max: 10, sort: "rentPrice", order: "desc", offset: 0]))
                break
            case "Area: Lowest first":
                list = (Place.findAllByTitlePlaceIlikeOrDescriptionIlike('%'+params.string+'%','%'+params.string+'%',[max: 10, sort: "area", order: "asc", offset: 0]))
                break
            case "Area: Highest first":
                list = (Place.findAllByTitlePlaceIlikeOrDescriptionIlike('%'+params.string+'%','%'+params.string+'%',[max: 10, sort: "area", order: "desc", offset: 0]))
                break
            default:
                print("default")
        }
        print(list)
        
        [list:list]
        //print(params.string)
        //print(Place.findAllByTitlePlaceIlikeOrDescriptionIlike('%'+params.string+'%','%'+params.string+'%'))
    }
}
